<?php

namespace App\Models\Subscribe;

use Illuminate\Database\Eloquent\Model;

class Status extends Model
{
    protected $table = 'jxt_subscribe_status';

    const CREATED_AT = 'create_at';
    const UPDATED_AT = null;

    public function getCreateAtAttribute()
    {
        return date('Y-m-d H:i:s', $this->attributes['end_time']);
    }

    /*public function getSubscribeTimeAttribute()
    {
        return date('Y-m-d H:i:s', $this->attributes['subscribe_time']);
    }

    public function getEndTimeAttribute()
    {
        return date('Y-m-d H:i:s', $this->attributes['end_time']);
    }*/

    public function getList()
    {
        return $this->select([$this->table.'.*','b.username','b.telephone'])
        ->leftJoin('jxt_xp_user as b','b.id',$this->table.'.user_id')
        ->orderBy('subscribe_time','desc');
    }

    public function info()
    {
        return $this->hasOne(Info::class,'user_id','user_id')
            ->select(['id','user_id','subscribe_time'])
            ->orderBy('subscribe_time', 'asc');
    }


}
